/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.KnowledgeBases.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jollylengkono.skripsi.KnowledgeBases.form.KnowledgeBasesUpdateForm;
import jollylengkono.skripsi.dao.KnowledgeBasesDao;
import jollylengkono.skripsi.dao.SubjectsDao;
import jollylengkono.skripsi.model.KnowledgeBases;
import jollylengkono.skripsi.model.Members;
import jollylengkono.skripsi.model.Subjects;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Nicholai
 */
public class KnowledgeBasesUpdate extends Action {
    private String FORWARD;
    private int STATE;

    public KnowledgeBasesUpdate() {
    }
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession sess = request.getSession(true);
        Members owner = (Members) sess.getAttribute("memberSessObject");
        KnowledgeBasesUpdateForm kbForm = (KnowledgeBasesUpdateForm) form;
        KnowledgeBases kb = new KnowledgeBases();
        kb.setDownloaded(kbForm.getDownloaded());
        kb.setFullContent(kbForm.getFullContent());
        kb.setHasDocument(kbForm.getHasDocument());
        kb.setId(kbForm.getId());
        kb.setOwner(owner);
        kb.setPublishes(kbForm.getPublishes());
        kb.setShortDescription(kbForm.getShortDescription());
        kb.setStatus(kbForm.getStatus());
        kb.setSubject((Subjects) new SubjectsDao().read(kbForm.getIdSubject()));
        kb.setTitle(kbForm.getTitle());
        kb.setUpdates(kbForm.getUpdates());
        this.STATE = new KnowledgeBasesDao().update(kb);
        if (this.STATE==1) {
            this.FORWARD = "success";
        } else {
            this.FORWARD = "fail";
        }
        return mapping.findForward(FORWARD);
    }
}
